from tools.driver import open_dingstock
from unittest import TestCase
from pages.recommend_page import RecommendPage
from pages.mine_page import MinePage
from pages.newest_page import NewestPage
import unittest
from time import sleep


class TestComment(TestCase):
    def setUp(self) -> None:
        self.driver = open_dingstock()
        self.recommendpage = RecommendPage(self.driver)
        self.minepage = MinePage(self.driver)
        self.newestpage = NewestPage(self.driver)

    def tearDown(self) -> None:
        sleep(1)

    def test_a_comment_trend(self):
        """测试动态二级评论"""
        level2_comment_text = '测试一下动态二级评论'
        self.recommendpage.switch_newest()
        sleep(1)
        self.newestpage.into_second_trend()
        origin_num = int(self.newestpage.get_comment_num())
        self.newestpage.send_level2_comment(level2_comment_text)
        new_num = int(self.newestpage.get_comment_num())
        assert new_num-1 == origin_num

    def test_b_look_comment_image(self):
        """测试查看动态二级评论图片"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.look_comment_image()
        assert self.newestpage.is_download_image_exist()

    def test_c_comment_like(self):
        """测试动态二级评论点赞及取消"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.into_level2_comment()
        self.newestpage.like_level2_comment()
        sleep(1)
        after_like = self.newestpage.is_level2_comment_like_exist()
        self.newestpage.like_level2_comment()
        sleep(1)
        after_cancel_like = self.newestpage.is_level2_comment_like_exist()
        assert after_like == True and after_cancel_like == False

    def test_d_comment_copy(self):
        """测试复制动态二级评论内容"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.copy_level2_comment()
        assert self.newestpage.is_text_toast_exist('已复制')

    def test_e_comment_report(self):
        """测试举报动态二级评论内容"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        self.newestpage.report_level2_comment()
        assert self.newestpage.is_text_toast_exist('举报成功')

    def test_f_delete_comment(self):
        """测试删除动态二级评论"""
        self.recommendpage.switch_newest()
        self.newestpage.into_second_trend()
        origin_comment_num = self.newestpage.get_comment_num()
        self.newestpage.into_level2_comment()
        self.newestpage.delete_level2_comment()
        new_comment_num = self.newestpage.get_comment_num()
        assert origin_comment_num != new_comment_num


if __name__ == '__main__':
    unittest.main()



